<!-- eslint-disable prettier/prettier -->
<!-- 用户编辑弹窗 -->
<template>
	<ele-modal
		:width="750"
		:visible="visible"
		:confirm-loading="loading"
		title="接收后状态无法返回，请谨慎操作"
		:body-style="{ paddingBottom: '8px' }"
		@update:visible="updateVisible"
		@ok="save"
	>
		<a-form :label-col="{ md: { span: 7 }, sm: { span: 4 }, xs: { span: 24 } }" :wrapper-col="{ md: { span: 17 }, sm: { span: 20 }, xs: { span: 24 } }">
			<a-row :gutter="24">
				<a-col :md="23" :sm="23" :xs="23">
					<a-form-item label="接收柜组">
            <a-select
            :options="options"
            allow-clear
            autocomplete="off"
            placeholder="请选择"
            v-model:value.string="form.store_group_code"
            @change="optionsUpdate"
          />
					</a-form-item>
				</a-col>
			</a-row>
		</a-form>
	</ele-modal>
</template>

<script setup>
  import { ref, reactive, onMounted } from 'vue';
  import { Form, message } from 'ant-design-vue';
  import { emailReg, phoneReg, identityReg } from 'ele-admin-pro';
  import {
    store_group_select,
    store_get_list
  } from '@/api/jewelry/receipts_stock';

  // 表格列配置
  const useForm = Form.useForm;

  const props = defineProps({
    // 弹窗是否打开
    visible: Boolean,
    // 编辑edit/新建add
    actionStatus: String,
    // 编辑数据id
    Code: Object,
    detail: String,
    over: Function
  });

  const emit = defineEmits(['done', 'update:visible']);
  const options = ref([]);
  // 提交状态
  const loading = ref(false);
  const form = reactive({
    gold_category_code: null,
    store_group_code: null
  });
  // 表单验证规则
  const rules = reactive({
    store_group_code: [
      {
        required: true,
        message: '请选择',
        type: 'string',
        trigger: 'change'
      }
    ]
  });
  onMounted(() => {
    getSelect();
  });
  const { validate, validateInfos } = useForm(form, rules);
  const getSelect = (val) => {
    store_group_select({
      filters: { store_code: props.Code.to_type_code },
      page: 1
    })
      .then((res) => {
        res.data.row_list.map((item) => {
          options.value.push({
            value: String(item.code),
            label: item.name
          });
        });
      })
      .catch((e) => {});
  };
  //切换柜组
  const optionsUpdate = (val) => {
    form.store_group_code = val;
  };
  /* 保存编辑 */
  const save = () => {
    if (props.detail && props.detail == 'detail') {
      //详情页引入时
      let data = {
        code: props.Code.code,
        receive_status: 1,
        store_group_code: form.store_group_code
      };
      props.over(data);
    } else {
      //列表页引入时
      emit('done', form.store_group_code);
    }
    updateVisible(false);
  };
  /* 更新visible */
  const updateVisible = (value) => {
    emit('update:visible', value);
  };
</script>
<style scoped></style>
